/*
 * @LastEditTime: 2023-03-16 22:50:47
 * @Method: 第k个数
 * @Description: 借助快慢指针,二分思想,找到第k个数
 */
package AcWing;

import java.util.Random;
import java.util.Scanner;
import java.util.Stack;

public class Solution786 {
    public static int partition(int[] nums, int l, int r) {
        if (l > r) {
            return -1;
        }
        if (l == r) {
            return l;
        }
        int rand = new Random().nextInt(r - l) + l;
        swap(nums, rand, r);
        int pivot = nums[r];
        int i = l;
        for (int j = l;j < r;j++) {
            if (nums[j] < pivot) {
                swap(nums, i, j);
                i++;
            }
        }
        swap(nums, i, r);
        return i;
    }

    public static void swap (int[] nums, int i, int j) {
        int t = nums[j];
        nums[j] = nums[i];
        nums[i] = t;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0;i < n;i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        int index = -1;
        Stack<Integer> s = new Stack<>();
        s.push(0);
        s.push(nums.length - 1);
        while (!s.isEmpty()) {
            int r = s.pop();
            int l = s.pop();
            index = partition(nums, l, r);
            if (index == k - 1) {
                break;
            } else if (index < k - 1) {
                s.push(index + 1);
                s.push(nums.length - 1);
            } else {
                s.push(0);
                s.push(index - 1);
            }
        }
        System.out.println(nums[k - 1]);
    }
}
